# 与列表类似，不同之处在于元组的元素不能修改
tuple1 = (1, 2, 3, False, "nihao")
print(tuple1)
print(type(tuple1))

tuple2 = (1,)  # 元组里只有一个元素时，加一个逗号
print(tuple2)
print(type(tuple2))

tuple3 = tuple()  # tuple():类型转换
print(tuple3)
print(type(tuple3))

tuple4 = ()
print(tuple4)
print(type(tuple4))

tuple5 = tuple("coding")  # str -> tuple
print(tuple5)
str1 = str(tuple5)  # tuple -> str
print(str1)
print(type(str1))

tuple6 = tuple([1, 2, 3, 4, 5])  # list -> tuple
print(tuple6)
list1 = list(tuple6)  # tuple -> list
print(list1)

print("=" * 50)
# 索引
print(tuple1[-1])
print(tuple1[0])
# 切片
print(tuple1[0:5:2])
print(tuple1[::-1])

print("=" * 50)
# 通用函数
print(len(tuple6))
print(min(tuple6), max(tuple6))

del tuple5
# print(tuple5)

print(tuple1 + tuple2)

print(tuple1 * 3)

print("nihao" in tuple1)

# 元组无法修改
# tuple1[1] = 5
# print(tuple1)


# 元组的常用方法
tuple7 = (34, 34, "hasaki", "world")
a = tuple7.count(34)
print(a)

b = tuple7.index("hasaki")
print(b)

print("=" * 50)
# 元组的遍历
for i in tuple7:
    print(i)

for index, value in enumerate(tuple7):
    print(index, value, sep=":")

for i in range(len(tuple7)):
    print(tuple7[i])